package com.heima.UserService.impl;

import com.heima.UserService.BrandService;
import com.heima.mapper.BrandMapper;
import com.heima.pojo.Brand;

import com.heima.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class BrandServiceImpl implements BrandService {
    @Override
    public List<Brand> getAll() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);
        List<Brand> brands = mapper.getAll();
        sqlSession.close();
        return brands;
    }

    @Override
    public Integer addBrand(Brand brand){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);
        Integer integer = mapper.addBrand(brand);
        sqlSession.close();
        return integer;
    }

    @Override
    public Brand brandById(Integer id) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);
        Brand brand = mapper.brandById(id);
        sqlSession.close();
        return brand;
    }

    @Override
    public Boolean updateBrand(Brand brand) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);
        Integer integer = mapper.updateBrand(brand);
        sqlSession.close();
        if (integer==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean deleteBrand(Integer id) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);
        Integer integer = mapper.deleteBrand(id);
        if (integer==1){
            return true;
        }else {
            return false;
        }
    }


}
